package com.gugu.procedure.common;


import java.util.ArrayList;
import java.util.List;

public class MessageResult<T> {
    private T data;

    public MessageResult(int code, String msg) {
        this.code = code;
        this.message = msg;
    }

    public MessageResult(int code, String msg, T object) {
        this.code = code;
        this.message = msg;
        this.data = object;
    }

    public MessageResult() {
    }

    public static MessageResult success() {
        return new MessageResult(200, "SUCCESS");
    }

    public static MessageResult success(String msg) {
        return new MessageResult(200, msg);
    }


    public static MessageResult success(String msg, Object data) {
        return new MessageResult(200, msg, data);
    }

    public static MessageResult error(int code, String msg) {
        return new MessageResult(code, msg);
    }

    public static MessageResult error(String msg) {
        return new MessageResult(500, msg);
    }

    private int code;
    private String message;

    private long total;
    private long totalPage;
    private List totalElement = new ArrayList();

    public long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(long totalPage) {
        this.totalPage = totalPage;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List getTotalElement() {
        return totalElement;
    }

    public void setTotalElement(List totalElement) {
        this.totalElement = totalElement;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public static MessageResult getSuccessInstance(String message, Object data) {
        MessageResult result = success(message);
        result.setData(data);
        return result;
    }

    public static MessageResult getSuccessInstance(Object data) {
        MessageResult result = success("success");
        result.setData(data);
        return result;
    }
}
